package com.putao.album.tinyalbum.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.putao.album.R;
import com.putao.album.base.PtBaseAdapter;
import com.putao.album.tag.view.TopRoundedBitmapDisplayer;
import com.putao.album.tinyalbum.bean.TinyAlbumItem;
import com.putao.album.util.BitmapHelper;
import com.putao.album.util.StringHelper;

import java.util.List;

/**
 * Created by jidongdong on 15/4/28.
 */
public class TinyAblumAdapter extends PtBaseAdapter {
    DisplayImageOptions options;

    public TinyAblumAdapter(Context context, List<TinyAlbumItem.AlbumItem> datalist) {
        super(context, datalist);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_tiny_album_item, null);
            viewHolder = new ViewHolder();
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.imageView);
            viewHolder.choiceness = (ImageView) convertView.findViewById(R.id.choiceness);
            viewHolder.tips_kiss = (ImageView) convertView.findViewById(R.id.tips_kiss);
            viewHolder.choose = (ImageView) convertView.findViewById(R.id.choose);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        TinyAlbumItem.AlbumItem item = (TinyAlbumItem.AlbumItem) getItem(position);

        if (item.isChoose()) {
            viewHolder.choose.setVisibility(View.VISIBLE);
            viewHolder.choiceness.setVisibility(View.INVISIBLE);
            viewHolder.tips_kiss.setVisibility(View.INVISIBLE);
        } else {
            viewHolder.choose.setVisibility(View.INVISIBLE);

            if (item.getIs_praise() > 0) {
                viewHolder.tips_kiss.setVisibility(View.VISIBLE);
            } else {
                viewHolder.tips_kiss.setVisibility(View.INVISIBLE);
            }

            if (item.getIs_choiceness() > 0) {
                viewHolder.choiceness.setVisibility(View.VISIBLE);
            } else {
                viewHolder.choiceness.setVisibility(View.INVISIBLE);
            }
        }

        DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(BitmapHelper.getLoadingDrawable()).showImageOnFail(BitmapHelper.getLoadingDrawable())
                .considerExifParams(true)
                .cacheInMemory(true).cacheOnDisk(true).bitmapConfig(Bitmap.Config.RGB_565).build();
        ImageLoader.getInstance().displayImage(item.getPhoto(), viewHolder.imageView, options);
        return convertView;
    }

    class ViewHolder {
        public ImageView imageView;
        public ImageView choiceness;
        public ImageView tips_kiss;
        public ImageView choose;
    }
}
